// 用户和权限相关类型
export interface User {
  id: string
  username: string
  email: string
  department: string
  roles: Role[]
  isActive: boolean
  lastLoginAt?: Date
  createdAt: Date
  updatedAt: Date
}

export interface Role {
  id: string
  name: string
  displayName: string
  description: string
  permissions: Permission[]
  isSystemRole: boolean
}

export interface Permission {
  id: string
  name: string
  resource: string
  action: string
  description: string
}

// 告警相关类型
export interface Alert {
  id: string
  alertname: string
  instance: string
  severity: 'critical' | 'high' | 'medium' | 'low'
  status: 'firing' | 'resolved' | 'acknowledged'
  startsAt: Date
  endsAt?: Date
  description: string
  summary: string
  labels: Record<string, string>
  annotations: Record<string, string>
  fingerprint: string
  aiAnalysis?: AIAnalysis
  assignedTo?: string
  ticketId?: string
}

export interface AIAnalysis {
  confidence: number
  tags: string[]
  category: string
  rootCause?: string
  impact: string
  recommendation: string
  priority: 'urgent' | 'high' | 'medium' | 'low'
  businessImpact: number
  urgency: number
  suggestedAssignee?: string
  suggestedTags: string[]
  similarIssues?: Alert[]
}

// 工单相关类型
export interface Ticket {
  id: string
  title: string
  description: string
  status: 'created' | 'assigned' | 'in_progress' | 'pending' | 'resolved' | 'closed' | 'reopened'
  priority: 'urgent' | 'high' | 'medium' | 'low'
  assignee?: User
  reporter: User
  watchers: User[]
  labels: string[]
  relatedAlert?: Alert
  linkedTickets: Ticket[]
  sla: SLAInfo
  timeline: TimelineEvent[]
  attachments: Attachment[]
  createdAt: Date
  updatedAt: Date
  resolvedAt?: Date
}

export interface SLAInfo {
  target: number // 目标解决时间（分钟）
  remaining: number // 剩余时间（分钟）
  status: 'on_track' | 'at_risk' | 'violated'
  compliance: number // 合规率
}

export interface TimelineEvent {
  id: string
  type: 'created' | 'assigned' | 'status_changed' | 'comment' | 'escalated'
  title: string
  description: string
  user: User
  timestamp: Date
  metadata?: Record<string, any>
}

export interface Attachment {
  id: string
  fileName: string
  fileSize: number
  mimeType: string
  url: string
  uploadedBy: User
  uploadedAt: Date
}

// 监控指标类型
export interface MetricData {
  name: string
  value: number
  unit?: string
  timestamp: Date
  labels: Record<string, string>
}

export interface MetricCard {
  title: string
  value: string | number
  unit?: string
  trend?: {
    direction: 'up' | 'down' | 'stable'
    percentage: number
  }
  color: 'success' | 'warning' | 'error' | 'info'
  sparkline?: number[]
  description?: string
}

// 知识库类型
export interface KnowledgeItem {
  id: string
  title: string
  content: string
  category: string
  tags: string[]
  author: User
  status: 'draft' | 'published' | 'archived'
  viewCount: number
  likeCount: number
  sources?: KnowledgeSource[]
  createdAt: Date
  updatedAt: Date
}

export interface KnowledgeSource {
  type: 'ticket' | 'alert' | 'document' | 'external'
  id: string
  title: string
  url?: string
}

export interface ChatMessage {
  id: string
  type: 'user' | 'ai'
  content: string
  timestamp: Date
  sources?: KnowledgeSource[]
  isLoading?: boolean
}

// 数据分析类型
export interface AnalyticsData {
  alertMetrics: {
    total: number
    resolved: number
    pending: number
    noiseFiltered: number
    averageResponseTime: number
    trend: number
  }
  ticketMetrics: {
    total: number
    resolved: number
    averageResolutionTime: number
    slaCompliance: number
    trend: number
  }
  systemMetrics: {
    uptime: number
    mtbf: number // 平均故障间隔时间
    mttr: number // 平均修复时间
    availability: number
  }
  teamMetrics: {
    ticketsResolved: number
    knowledgeCreated: number
    automationRate: number
    efficiency: number
  }
}

// API响应类型
export interface ApiResponse<T = any> {
  success: boolean
  data: T
  message?: string
  error?: string
  pagination?: {
    current: number
    pageSize: number
    total: number
  }
}

export interface PaginationParams {
  current: number
  pageSize: number
  total?: number
}

// 通用过滤器类型
export interface FilterParams {
  search?: string
  status?: string[]
  severity?: string[]
  assignee?: string[]
  dateRange?: [Date, Date]
  tags?: string[]
}

// 图表数据类型
export interface ChartData {
  labels: string[]
  datasets: {
    label: string
    data: number[]
    backgroundColor?: string | string[]
    borderColor?: string | string[]
    borderWidth?: number
    fill?: boolean
  }[]
}

// 系统配置类型
export interface SystemConfig {
  general: {
    siteName: string
    timezone: string
    language: string
  }
  monitoring: {
    prometheusUrl: string
    refreshInterval: number
    retentionDays: number
  }
  llm: {
    provider: 'openai' | 'claude' | 'custom'
    apiKey: string
    model: string
    temperature: number
  }
  notifications: {
    email: boolean
    sms: boolean
    webhook: boolean
    channels: NotificationChannel[]
  }
}

export interface NotificationChannel {
  id: string
  name: string
  type: 'email' | 'sms' | 'webhook' | 'dingtalk'
  config: Record<string, any>
  enabled: boolean
}

// 路由类型（Vue版本）
export interface RouteConfig {
  path: string
  name: string
  component: any
  title: string
  icon?: any
  children?: RouteConfig[]
  requireAuth?: boolean
  permissions?: string[]
}
